package edu.mcw.rgd.clinminer.web.userrole;

import com.spaceapplications.vaadin.addon.eventtimeline.event.BasicEvent;

/**
 * Extension of BasicEvent for Vaadin timeline that supports de-duplication of
 * events in sets and list through a custom implementation @{@link #hashCode()}
 * and @{@link #equals(Object)}
 * 
 * @author Tomasz Adamusiak <tadamusiak@mcw.edu>
 * 
 */
public class ComparableEvent extends BasicEvent {

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((getCaption() == null) ? 0 : getCaption().hashCode());
		result = prime
				* result
				+ ((getDescription() == null) ? 0 : getDescription()
						.hashCode());
		result = prime * result
				+ ((getEnd() == null) ? 0 : getEnd().hashCode());
		result = prime * result
				+ ((getEventId() == null) ? 0 : getEventId().hashCode());
		result = prime * result
				+ ((getStart() == null) ? 0 : getStart().hashCode());
		result = prime
				* result
				+ ((getStyleName() == null) ? 0 : getStyleName().hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		ComparableEvent other = (ComparableEvent) obj;
		if (getCaption() == null) {
			if (other.getCaption() != null) {
				return false;
			}
		} else if (!getCaption().equals(other.getCaption())) {
			return false;
		}
		if (getDescription() == null) {
			if (other.getDescription() != null) {
				return false;
			}
		} else if (!getDescription().equals(other.getDescription())) {
			return false;
		}
		if (getEnd() == null) {
			if (other.getEnd() != null) {
				return false;
			}
		} else if (!getEnd().equals(other.getEnd())) {
			return false;
		}
		if (getEventId() == null) {
			if (other.getEventId() != null) {
				return false;
			}
		} else if (!getEventId().equals(other.getEventId())) {
			return false;
		}
		if (getStart() == null) {
			if (other.getStart() != null) {
				return false;
			}
		} else if (!getStart().equals(other.getStart())) {
			return false;
		}
		if (getStyleName() == null) {
			if (other.getStyleName() != null) {
				return false;
			}
		} else if (!getStyleName().equals(other.getStyleName())) {
			return false;
		}
		return true;
	}
}